import request from '@/utils/request'

export default {
  getUserList(query) {
    return request('/user/list', {
      params: {
        index: query.index,
        limit: query.limit
      }
    });
  },
  deleteUser(username){
    return request.post('/user/del', {
      name: username
    });
  },
  addUser(user) {
    return request.post('/user/add', user);
  },
  modifyUser(user) {
    return request.post('/user/update', user);
  },
  changePassword(old_pwd,new_pwd){
    return request.post('/user/password',{old_pwd,new_pwd});
  },
  uploadAvatar(data, file_name = 'avatar.png') {
    let param = new FormData();
    param.append('file', data, file_name);
    let config = {
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    };

    return request.post('/user/avatar', param, config);
  }
}